<template>
  <div style="min-height: calc(100vh - 230px);">
    <el-row >
      <el-col :span="24">
        <el-card shadow="never" :body-style="{ height: 'calc(100vh - 230px)'}">
          <el-alert
            title="图标选择器演示"
            type="success"
            :closable="false"
          >
          </el-alert>
          <el-popover
            placement="top-start"
            width="292"
            trigger="hover">
            <el-button slot="reference">
              <i :class="firstIcon" class="first-icon"></i>更多菜单<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-row :gutter="20" >
              <el-col :span="24">
                <div class="top-panel">
                  <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-form-item >
                      <el-input v-model="formInline.iconName"></el-input>
                    </el-form-item>
                    <el-form-item>
                      <el-button type="primary" @click="onSubmit">查询</el-button>
                    </el-form-item>
                  </el-form>
                </div>
              </el-col>
            </el-row>
            <el-row class="icon-box">
              <el-col :span="6"
                      @click.native="getIcon(item.name)"
                      v-for="(item,index) in iconList.slice((pages.pageNum-1)*pages.pageSize,pages.pageNum*pages.pageSize)" :key="index">
                <el-card shadow="hover" :body-style="{ padding:'20px',height: '20px',width:'50px'}">
                  <i :class="item.name"></i>
                </el-card>
              </el-col>
            </el-row>
            <el-row >
              <el-col :span="24">
                <Pagination
                  :total="iconList.length" :pageNum.sync="pages.pageNum"
                  :limit.sync="pages.pageSize"
                  :layout="`total, prev, next`"
                ></Pagination>
              </el-col>
            </el-row>
          </el-popover>
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import { iconList } from '@/utils/icon'
import Pagination from '@/components/Pagination/Pagination'
export default {
  name: 'iconSelector',
  components:{Pagination},
  data() {
    return {
      iconList: iconList,
      dataList:iconList,
      formInline: {
        iconName: ''
      },
      pages: {
        pageNum: 1,
        pageSize: 16
      },
      firstIcon:''
    }
  },
  methods: {
    getIcon(name){
      this.firstIcon = name
    },
    onSubmit() {
      let list = []
      this.iconList = this.dataList
      for (let i = 0; i < this.iconList.length; i++) {
        if (this.iconList[i].name.indexOf(this.formInline.iconName)>= 0){
          list.push(this.iconList[i])
        }
      }
      this.iconList = list
    },
  },
  mounted() {
    this.firstIcon = iconList[0].name
  }
}
</script>

<style scoped lang="scss">
.el-alert {
  margin-bottom: 20px;
}

.first-icon {
  font-size: 14px;
  vertical-align: -2px;
  margin-right: 2px;
}
.el-popover{
  .top-panel {
    display: flex;
    flex-wrap: wrap;
    align-content: center;
    align-items: center;
    justify-content: flex-start;
    min-height: 32px;
    margin: 0 0 10px 0;

  }

}
.icon-box{
  .el-col{
    margin-bottom: 20px;
  }
  .el-card{
    width: 52px;
    height: 42px;
    text-align: center;

  }
  ::v-deep.el-card .el-card__body{
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 20px;
    cursor: pointer;
    i{
      font-size: 28px;
      color: gray;
      text-align: center;
      vertical-align: middle;
      pointer-events: none;
      cursor: pointer;
    }
  }
}
::v-deep.el-row {
  margin-bottom: 0;
  &:last-child {
    margin-bottom: 0;
  }
}
</style>
